﻿@model CustomerUserSettingsModel

@using Nop.Core.Domain.Customers;
@using Nop.Services

@{
    //page title
    ViewBag.Title = T("Admin.Configuration.Settings.CustomerUser").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Customer and user settings");
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <div class="content-header clearfix">
        <h1 class="pull-left">
            @T("Admin.Configuration.Settings.CustomerUser")
        </h1>
        <div class="pull-right">
            <button type="submit" name="save" class="btn bg-blue">
                <i class="fa fa-floppy-o"></i>
                @T("Admin.Common.Save")
            </button>
        </div>
    </div>
    @Html.ValidationSummary(false)

    <script>
        $(document).ready(function () {
            bindBootstrapTabSelectEvent('customersettings-edit');
        });
    </script>

    <div class="content">
        <div class="form-horizontal">
            @Html.Action("Mode", "Setting")

            <div id="customersettings-edit" class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                    @Html.RenderBootstrapTabHeader("tab-customer", @T("Admin.Configuration.Settings.CustomerUser.CustomerSettings"), true)
                    @Html.RenderBootstrapTabHeader("tab-customerformfields", @T("Admin.Configuration.Settings.CustomerUser.CustomerFormFields"))
                </ul>
                <div class="tab-content">
                    @Html.RenderBootstrapTabContent("tab-customer", @TabCustomerSettings(), true)
                    @Html.RenderBootstrapTabContent("tab-customerformfields", @TabCustomerFormFields())
                </div>
            </div>
        </div>
    </div>

    {
        //custom tabs
        var eventMessage = new AdminTabStripCreated(this.Html, "customersettings-edit");
        EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
        foreach (var eventBlock in eventMessage.BlocksToRender)
        {
            @eventBlock
        }
    }

    @*save selected tab name*@
    <input type="hidden" id="selected-tab-name" name="selected-tab-name" value="@(Html.GetSelectedTabName())">
}

@helper TabCustomerSettings()
{
    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-heading">
                @T("Admin.Configuration.Settings.CustomerUser.BlockTitle.Common")
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.UserRegistrationType)
                    </div>
                    <div class="col-md-9">
                        @Html.NopDropDownListFor(model => model.CustomerSettings.UserRegistrationType, ((UserRegistrationType)Model.CustomerSettings.UserRegistrationType).ToSelectList())
                        @Html.ValidationMessageFor(model => model.CustomerSettings.UserRegistrationType)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.NotifyNewCustomerRegistration)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.NotifyNewCustomerRegistration)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.NotifyNewCustomerRegistration)
                    </div>
                </div>
                
            </div>
        </div>
        <div class="panel panel-default advanced-setting">
            <div class="panel-heading">
                @T("Admin.Configuration.Settings.CustomerUser.BlockTitle.Password")
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.PasswordMinLength)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.PasswordMinLength)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.PasswordMinLength)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.UnduplicatedPasswordsNumber)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.UnduplicatedPasswordsNumber)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.UnduplicatedPasswordsNumber)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.DefaultPasswordFormat)
                    </div>
                    <div class="col-md-9">
                        @Html.NopDropDownListFor(model => model.CustomerSettings.DefaultPasswordFormat, ((PasswordFormat)Model.CustomerSettings.DefaultPasswordFormat).ToSelectList())
                        @Html.ValidationMessageFor(model => model.CustomerSettings.DefaultPasswordFormat)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.PasswordLifetime)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.PasswordLifetime)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.PasswordLifetime)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.PasswordRecoveryLinkDaysValid)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.PasswordRecoveryLinkDaysValid)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.PasswordRecoveryLinkDaysValid)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.FailedPasswordAllowedAttempts)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.FailedPasswordAllowedAttempts)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.FailedPasswordAllowedAttempts)
                    </div>
                </div>
                <div class="form-group" id="pnlFailedPasswordLockoutMinutes">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.FailedPasswordLockoutMinutes)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.FailedPasswordLockoutMinutes)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.FailedPasswordLockoutMinutes)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.EnteringEmailTwice)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.EnteringEmailTwice)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.EnteringEmailTwice)
                    </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default advanced-setting">
            <div class="panel-heading">
                @T("Admin.Configuration.Settings.CustomerUser.BlockTitle.Account")
            </div>
            <div class="panel-body">
                <div class="form-group advanced-setting" id="pnlAllowUsersToChangeUsernames">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.AllowUsersToChangeUsernames)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.AllowUsersToChangeUsernames)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.AllowUsersToChangeUsernames)
                    </div>
                </div>
                <div class="form-group advanced-setting" id="pnlCheckUsernameAvailability">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.CheckUsernameAvailabilityEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.CheckUsernameAvailabilityEnabled)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.CheckUsernameAvailabilityEnabled)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.CustomerNameFormat)
                    </div>
                    <div class="col-md-9">
                        @Html.NopDropDownListFor(model => model.CustomerSettings.CustomerNameFormat, ((CustomerNameFormat)Model.CustomerSettings.CustomerNameFormat).ToSelectList())
                        @Html.ValidationMessageFor(model => model.CustomerSettings.CustomerNameFormat)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.AllowCustomersToUploadAvatars)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.AllowCustomersToUploadAvatars)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.AllowCustomersToUploadAvatars)
                    </div>
                </div>
                <div class="form-group" id="pnlDefaultAvatarEnabled">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.DefaultAvatarEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.DefaultAvatarEnabled)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.DefaultAvatarEnabled)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.StoreLastVisitedPage)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.StoreLastVisitedPage)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.StoreLastVisitedPage)
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                $(document).ready(function () {
                    $("#@Html.FieldIdFor(model => model.CustomerSettings.AllowCustomersToUploadAvatars)").click(toggleAvatar);

                    toggleAvatar();
                });

                function toggleAvatar() {
                    if ($('#@Html.FieldIdFor(model => model.CustomerSettings.AllowCustomersToUploadAvatars)').is(':checked')) {
                        $('#pnlDefaultAvatarEnabled').show();
                    } else {
                        $('#pnlDefaultAvatarEnabled').hide();
                    }
                }
            </script>
        </div>
    </div>
}

@helper TabCustomerFormFields()
{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#@Html.FieldIdFor(model => model.CustomerSettings.DateOfBirthEnabled)").click(toggleCustomerRequiredFormField);
            $("#@Html.FieldIdFor(model => model.CustomerSettings.DateOfBirthRequired)").click(toggleCustomerRequiredFormField);

            toggleCustomerRequiredFormField();
        });

        

        function toggleCustomerRequiredFormField() {
            if ($('#@Html.FieldIdFor(model => model.CustomerSettings.DateOfBirthEnabled)').is(':checked')) {
                $('#pnlCustomerDateOfBirthRequired').show();
            } else {
                $('#pnlCustomerDateOfBirthRequired').hide();
            }

            if ($('#@Html.FieldIdFor(model => model.CustomerSettings.DateOfBirthEnabled)').is(':checked') &&
                $('#@Html.FieldIdFor(model => model.CustomerSettings.DateOfBirthRequired)').is(':checked')) {
                $('#pnlDateOfBirthMinimumAge').show();
            } else {
                $('#pnlDateOfBirthMinimumAge').hide();
            }

        }

    </script>

    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-heading">
                @T("Admin.Configuration.Settings.CustomerUser.BlockTitle.DefaultFields")
            </div>
            <div class="panel-body">
                <p>
                    <em>@T("Admin.Configuration.Settings.CustomerUser.CustomerFormFields.Description")</em>
                </p>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.GenderEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.GenderEnabled)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.GenderEnabled)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.DateOfBirthEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.DateOfBirthEnabled)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.DateOfBirthEnabled)
                    </div>
                </div>
                <div class="form-group" id="pnlCustomerDateOfBirthRequired">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.DateOfBirthRequired)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.DateOfBirthRequired)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.DateOfBirthRequired)
                    </div>
                </div>
                <div class="form-group" id="pnlDateOfBirthMinimumAge">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.CustomerSettings.DateOfBirthMinimumAge)
                    </div>
                    <div class="col-md-9">
                        @Html.NopEditorFor(model => model.CustomerSettings.DateOfBirthMinimumAge)
                        @Html.ValidationMessageFor(model => model.CustomerSettings.DateOfBirthMinimumAge)
                    </div>
                </div>
            </div>
        </div>
    </div>
}
